home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / FromTheMag / JW FLV MEDIA PLAYER 4.2 / mediaplayer.exe / player.swf / scripts / com / jeroenwijering / player / SPLoader.as < prev    next >
Text File  |  2008-11-04  |  5KB  |  171 lines

  1. package com.jeroenwijering.player
  2. {
  3.    import com.jeroenwijering.events.SPLoaderEvent;
  4.    import com.jeroenwijering.utils.Draw;
  5.    import flash.display.Loader;
  6.    import flash.display.MovieClip;
  7.    import flash.events.Event;
  8.    import flash.events.EventDispatcher;
  9.    import flash.events.IOErrorEvent;
  10.    import flash.net.URLRequest;
  11.    import flash.system.ApplicationDomain;
  12.    import flash.system.LoaderContext;
  13.    import flash.system.SecurityDomain;
  14.    
  15.    public class SPLoader extends EventDispatcher
  16.    {
  17.        
  18.       
  19.       private var done:Number;
  20.       
  21.       private var loader:Loader;
  22.       
  23.       private var basedir:String = "http://plugins.longtailvideo.com/";
  24.       
  25.       private var player:MovieClip;
  26.       
  27.       public function SPLoader(param1:MovieClip)
  28.       {
  29.          basedir = "http://plugins.longtailvideo.com/";
  30.          super();
  31.          player = param1;
  32.       }
  33.       
  34.       public function loadSkin(param1:String = null) : void
  35.       {
  36.          if(param1)
  37.          {
  38.             loadSWF(param1,true);
  39.          }
  40.          else
  41.          {
  42.             hideElements(player.skin);
  43.             dispatchEvent(new SPLoaderEvent(SPLoaderEvent.SKIN));
  44.          }
  45.       }
  46.       
  47.       private function skinError(param1:IOErrorEvent = null) : void
  48.       {
  49.          player.skin = player["player"];
  50.          hideElements(player.skin);
  51.          dispatchEvent(new SPLoaderEvent(SPLoaderEvent.SKIN));
  52.       }
  53.       
  54.       private function pluginHandler(param1:Event) : void
  55.       {
  56.          var evt:Event = param1;
  57.          try
  58.          {
  59.             evt.target.content.initializePlugin(player.view);
  60.             evt.target.loader.visible = true;
  61.          }
  62.          catch(err:Error)
  63.          {
  64.             player.view.sendEvent("TRACE"," plugin: " + err.message);
  65.          }
  66.          --done;
  67.          if(done == 0)
  68.          {
  69.             dispatchEvent(new SPLoaderEvent(SPLoaderEvent.PLUGINS));
  70.          }
  71.       }
  72.       
  73.       private function hideElements(param1:MovieClip) : void
  74.       {
  75.          var _loc2_:Number = NaN;
  76.          _loc2_ = 0;
  77.          while(_loc2_ < param1.numChildren)
  78.          {
  79.             param1.getChildAt(_loc2_).visible = false;
  80.             _loc2_++;
  81.          }
  82.       }
  83.       
  84.       public function loadPlugins(param1:String = null) : void
  85.       {
  86.          var _loc2_:Array = null;
  87.          var _loc3_:Number = NaN;
  88.          if(param1)
  89.          {
  90.             _loc2_ = param1.split(",");
  91.             done = _loc2_.length;
  92.             _loc3_ = 0;
  93.             while(_loc3_ < _loc2_.length)
  94.             {
  95.                loadSWF(_loc2_[_loc3_],false);
  96.                _loc3_++;
  97.             }
  98.          }
  99.          else
  100.          {
  101.             dispatchEvent(new SPLoaderEvent(SPLoaderEvent.PLUGINS));
  102.          }
  103.       }
  104.       
  105.       private function pluginError(param1:IOErrorEvent) : void
  106.       {
  107.          player.view.sendEvent("TRACE"," plugin: " + param1.text);
  108.          --done;
  109.          if(done == 0)
  110.          {
  111.             dispatchEvent(new SPLoaderEvent(SPLoaderEvent.PLUGINS));
  112.          }
  113.       }
  114.       
  115.       private function skinHandler(param1:Event) : void
  116.       {
  117.          if(param1.target.content["player"])
  118.          {
  119.             player.skin = MovieClip(param1.target.content["player"]);
  120.             Draw.clear(player);
  121.             player.addChild(player.skin);
  122.             hideElements(player.skin);
  123.             dispatchEvent(new SPLoaderEvent(SPLoaderEvent.SKIN));
  124.          }
  125.          else
  126.          {
  127.             skinError();
  128.          }
  129.       }
  130.       
  131.       public function loadSWF(param1:String, param2:Boolean) : void
  132.       {
  133.          var _loc3_:Loader = null;
  134.          var _loc4_:LoaderContext = null;
  135.          if(param1.substr(-4) != ".swf")
  136.          {
  137.             param1 += ".swf";
  138.          }
  139.          _loc3_ = new Loader();
  140.          if(param2)
  141.          {
  142.             _loc3_.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,skinError);
  143.             _loc3_.contentLoaderInfo.addEventListener(Event.INIT,skinHandler);
  144.          }
  145.          else
  146.          {
  147.             player.skin.addChild(_loc3_);
  148.             _loc3_.visible = false;
  149.             _loc3_.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,pluginError);
  150.             _loc3_.contentLoaderInfo.addEventListener(Event.INIT,pluginHandler);
  151.          }
  152.          if(player.loaderInfo.url.indexOf("http") == 0)
  153.          {
  154.             _loc4_ = new LoaderContext(true,ApplicationDomain.currentDomain,SecurityDomain.currentDomain);
  155.             if(param2)
  156.             {
  157.                _loc3_.load(new URLRequest(param1),_loc4_);
  158.             }
  159.             else
  160.             {
  161.                _loc3_.load(new URLRequest(basedir + param1),_loc4_);
  162.             }
  163.          }
  164.          else
  165.          {
  166.             _loc3_.load(new URLRequest(param1));
  167.          }
  168.       }
  169.    }
  170. }
  171.